<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use App\Goods;
use Carbon\Carbon;
Route::get('/', function (\Illuminate\Http\Request $request) {
    $where = [];
array_push($where, ['goods.status', '=', 1]);
    if ($request->cat_id) {
        array_push($where, ['goods.cat_id', '=', $request->cat_id]);
    }


    $expiresAt = Carbon::now()->addMinutes(30);
    $goods = Cache::remember('idx-' . $request->cat_id, $expiresAt, function() use ($where) {
        return Goods::where($where)->orderBy('goods_id', 'desc')->paginate(40);
    });


    return view('welcome', [
        'categories' => Goods::getCateogries(),
        'goods' => $goods,
    ]);
});
